#include "soundcard.h"
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
//#include <ortp/ortp.h>

int sound_init(int format)
{
		int fd;
		fd=open("/dev/dsp",O_WRONLY);
		if (fd<0){
			perror("Can't open /dev/audio");
			return -1;
		}
		ioctl(fd,SNDCTL_DSP_RESET,0);
		ioctl(fd,SNDCTL_DSP_SPEED,44100);
		ioctl(fd,SNDCTL_DSP_STEREO,1);
		ioctl(fd,SNDCTL_DSP_CHANNELS,2);
		ioctl(fd,SNDCTL_DSP_SETFMT,AFMT_S16_LE);
		return fd;
}

int main(int argc,char *argv[])
{
int fd_audio;
int file_fd;
char buff[1024];
int count = 0;
		fd_audio = sound_init(1);
		file_fd = open(argv[1],O_RDONLY);
		if (file_fd<0){
			printf("Can't open %s\n",argv[1]);
			return -1;
		}
		while(1)
		{
			//memset(buff,0,1024);
			count = 0;
			count = read(file_fd,buff,1024);
			if(count)
			{
				printf("read date num:%d\n",count);
				write(fd_audio,buff,count);
			}
			else
				break;


		}

}
//fd=open("/dev/audio",O_WRONLY);
										//	return fd;	
										//	}
